/*
 * Copyright © 2022-now 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springcloud.user.config;

import cn.denvie.springcloud.outside.NacosLoadBalancerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

/**
 * UserCenterConfig。
 *
 * @author Denvie
 * @date 2022/3/29
 * @since 1.0.0
 */
@Configuration
@LoadBalancerClients(
        {@org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient(
                name = "order-center", configuration = NacosLoadBalancerConfig.class)}
)
public class UserCenterConfig {
    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setInterceptors(Collections.singletonList(new LoadBalancerInterceptor(loadBalancerClient)));
        return restTemplate;
    }
}
